package com.cc.AOP.lianxi;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Slf4j
@Aspect
//@Component
public class MyAspect1 {


    //切入点方法（公共的切入点表达式）
    @Pointcut("execution(* com.cc.service.*.*(..))")
    private void pt(){}
    //前置通知



    @Before("pt()")
    //@Before("execution(* com.cc.service. *.* (..))")
    public void before(){
        log.info("MyAspect1.before()");
    }


    @Around("pt()")
    //@Around("execution(* com.cc.service. *.* (..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("around before...");
        Object result=joinPoint.proceed();

        log.info("around after...");
        return result;
    }



    //后置通知（程序在正常执行和异常情况下，都会执行）
    @After("pt()")
    //@After("execution(* com.cc.service.*.*(..))")
    public void after(JoinPoint joinPoint){
        log.info("after ...");
    }

    //返回后通知（程序在正常执行的情况下，会执行的后置通知）

    @AfterReturning("pt()")
    //@AfterReturning("execution(* com.cc.service.*.*(..))")
    public void afterReturning(JoinPoint joinPoint){
        log.info("afterReturning ...");
    }



    //异常通知（程序在出现异常的情况下，执行的后置通知）
    @AfterThrowing("pt()")
   // @AfterThrowing("execution(* com.cc.service.*.*(..))")
    public void afterThrowing(JoinPoint joinPoint){
        log.info("afterThrowing ...");
    }
}
